<!DOCTYPE html>
<html><head>
	    <meta charset="utf-8">
    <title>ThinkPHP5.0</title>

    <meta name="description" content="Dashboard">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--Basic Styles-->
    <link href="__STATIC__/style/bootstrap.css" rel="stylesheet">
    <link href="__STATIC__/style/font-awesome.css" rel="stylesheet">
    <link href="__STATIC__/style/weather-icons.css" rel="stylesheet">

    <!--Beyond styles-->
    <link id="beyond-link" href="__STATIC__/style/beyond.css" rel="stylesheet" type="text/css">
    <link href="__STATIC__/style/demo.css" rel="stylesheet">
    <link href="__STATIC__/style/typicons.css" rel="stylesheet">
    <link href="__STATIC__/style/animate.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/plus/layui/css/layui.css">
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    
</head>
<body>
	<!-- 头部 -->
	{include file="Common/head"}
	<!-- /头部 -->
	
	<div class="main-container container-fluid">
		<div class="page-container">
			            <!-- Page Sidebar -->
                        <div class="page-sidebar" id="sidebar">
                                <!-- Page Sidebar Header-->
                                <div class="sidebar-header-wrapper">
                                    <input class="searchinput" type="text">
                                    <i class="searchicon fa fa-search"></i>
                                    <div class="searchhelper">Search Reports, Charts, Emails or Notifications</div>
                                </div>
                                <!-- /Page Sidebar Header -->
                                <!-- Sidebar Menu -->
                                {include file="common/left"}
                                <!-- /Sidebar Menu -->
                            </div>
            <!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                                        <li>
                        <a href="{:url('index/index')}">系统</a>
                    </li>
                                        <li>
                        <a href="{:url('ad/index')}">广告管理</a>
                    </li>
                                        <li class="active">添加广告</li>
                                        </ul>
                </div>
                <!-- /Page Breadcrumb -->

                <!-- Page Body -->
                <div class="page-body">
                    
<div class="row">
    <div class="col-lg-12 col-sm-12 col-xs-12">
        <div class="widget">
            <div class="widget-header bordered-bottom bordered-blue">
                <span class="widget-caption">新增广告</span>
            </div>
            <div class="widget-body">
                <div id="horizontal-form">
                    <form class="form-horizontal" role="form" action="{:url('ad/save')}" method="post"
                        enctype="multipart/form-data">
            
            
                        <div class="form-group">
                            <label for="group_id" class="col-sm-2 control-label no-padding-right">所属广告位</label>
                            <div class="col-sm-6">
                                <select name="did" style="width: 100%;">
                                    <option value="">选择广告位</option>
                                    {volist name="pos" id="vo"}
                                    <option value="{$vo.id}">{$vo.name}</option>
                                    {/volist}
            
                                </select>
                            </div>
                        </div>
            
                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">广告名</label>
                            <div class="col-sm-6">
                                <input class="form-control" placeholder="" name="adname" type="text">
                            </div>
                            <p class="help-block col-sm-4 red">* 必填</p>
                        </div>
            
                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">是否启用</label>
                            <div class="col-sm-6">
            
                                <!-- 单选按钮 -->
                                <div class="radio" style="float:left; padding-left:10px;">
                                    <label>
                                        <input checked="checked" name="on" value="1" class="colored-blue" type="radio">
                                        <span class="text">是</span>
                                    </label>
                                </div>
                                <!-- 单选按钮 -->
                                <div class="radio" style="float:left; padding-left:10px;">
                                    <label>
                                        <input name="on" value="2" class="colored-blue" type="radio">
                                        <span class="text">否</span>
                                    </label>
                                </div>
                            </div>
                            <p class="help-block col-sm-4 red">* 必填</p>
                        </div>
            
                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">广告类型</label>
                            <div class="col-sm-6">
            
                                <!-- 单选按钮 -->
                                <div class="radio" style="float:left; padding-left:10px;">
                                    <label>
                                        <input id="img" checked="checked" name="type" value="1" class="colored-blue" type="radio">
                                        <span class="text">图片</span>
                                    </label>
                                </div>
                                <!-- 单选按钮 -->
                                <div class="radio" style="float:left; padding-left:10px;">
                                    <label>
                                        <input id="lh" name="type" value="2" class="colored-blue" type="radio">
                                        <span class="text">轮换</span>
                                    </label>
                                </div>
                            </div>
                            <p class="help-block col-sm-4 red">* 必填</p>
                        </div>
            
                        <div class="img">
                            <div class="form-group">
                                <label for="username" class="col-sm-2 control-label no-padding-right">图片</label>
                                <div class="col-sm-6">
                                        <button type="button" class="layui-btn" id="layimg"
                                        style="background:#2dc3e8;">
                                        <i class="layui-icon">&#xe67c;</i>上传图片
                                    </button>
                                    <input type="hidden" value="" id="imgcate" name="pic">
                                    <div id="thumb_list" style="height:80px;display: none;"></div>
                                </div>
                                <p class="help-block col-sm-4 red">* 必填</p>
                            </div>
                            
                            <div class="form-group">
                                <label for="username" class="col-sm-2 control-label no-padding-right">链接</label>
                                <div class="col-sm-6">
                                    <input class="form-control" placeholder="" name="url" type="text">
                                </div>
                                <p class="help-block col-sm-4 red">* 必填</p>
                            </div>
                        </div>
        
    
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-default">保存信息</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
		</div>	
	</div>

	    <!--Basic Scripts-->
    <script src="__STATIC__/style/jquery_002.js"></script>
    <script src="__STATIC__/style/bootstrap.js"></script>
    <script src="__STATIC__/style/jquery.js"></script>
    <!--Beyond Scripts-->
    <script src="__STATIC__/plus/layer/layer.js"></script>
    <script src="__STATIC__/plus/layui/layui.js"></script>
    <script>
        
        layui.use(['upload','form'], function () {
            var upload = layui.upload;
            var form = layui.form;    
            //执行实例
            var uploadInst = upload.render({
                elem: '#layimg' //绑定元素
                 , accept: 'images' //允许上传的文件类型
                , field: "picfile"
                , size: 2048 //最大允许上传的文件大小
                , url: "{:url('admin/common/uploadimg')}" //上传接口
                , done: function (res) {
                //    console.log(res);return false;
                    setTimeout(function () {

                        if (res.code == 1) {
                            layer.msg(res.msg, {icon:1});
                           
                            // var pic = $('input[name=pic]').val();
                            // if (pic == "") {
                                $('input[name=pic]').val(res.path);
                            // } else {
                            //     $('input[name=pic]').val(pic + "," + res.path);
                            // }
                            var str;
                            str = "<span>";
                            str = str + '<img src="/' + res.path + '" alt="" height="80">';
                            str = str + '<button type="button" style="margin-top:-60px;margin-left:-27px;" class="layui-btn layui-btn-danger layui-btn-mini delimg" onclick="delimg(this);" data="' + res.path + '">';
                            str = str + '<i class="layui-icon">&#xe640;</i>';
                            str = str + '</button>';
                            str = str + '</span>';
                            $('#thumb_list').append(str);
                            $('#thumb_list').show();
                        } else {
                            layer.msg(res.msg, { icon: 2 });
                        }
                        layer.closeAll('loading'); //关闭loading
                    }, 1000);
                }
                , error: function () {
                    //请求异常回调
                }
            });
        });
        function delimg(o){
            var url=$(o).attr('data');
            $.post("{:url('common/delImg')}",{'url':url},function(res){
                console.log(res)
                if(res.code==1||res.code==2){
                    $('input[name=pic]').val("");
                    //删除/移除缩略图
                   $(o).parent().remove();
                   $('#thumb_list').hide();
                   layer.msg(res.msg,{icon:1});
                }
                if(rse.code==0){
                    layer.msg(res.msg,{icon:2});
                }
            });
        }
       
    </script>

    


</body></html>